//-----------注册页js-------------------
jQuery.noConflict();
jQuery(function($){
	var $zhuce=true;
	$("#register input").on("focus",function(){
		$(this).parent("label").css("border-color","#888");
		$(this).parent().next().css("visibility","hidden").find("span").text("");
		$zhuce=true;
	})
	$("#register #zhuce-phonenumber").on("blur",function(){
		var $phonenum=$(this).val();
		var $turn=false;
		if($(this).val()==""){
			$(this).parent().next().css("visibility","visible").find("span").text("手机号码用来登录，不能为空！");
		}else if(!/^1[\d]{10}$/.test($phonenum)){	
			$(this).parent().next().css("visibility","visible").find("span").text("手机号码格式错误！");
		}else{
			$turn=true;
		}
		if($turn==false){
			$(this).parent("label").css("border-color","#d10048");
			$zhuce=false;
		}
	})
	$("#register #zhuce-yanzheng,#phone-yanzheng").on("blur",function(){
		var $num=$(this).val();
		var $turn=false;
		if($(this).val()==""){
			$(this).parent().next().css("visibility","visible").find("span").text("验证码不能为空！");
		}else if($num.length!=4){
			$(this).parent().next().css("visibility","visible").find("span").text("验证码长度不对！");
		}else{
			$turn=true;
		}
		if($turn==false){
			$(this).parent("label").css("border-color","#d10048");
			$zhuce=false;
		}
	})
	$("#zhuce-password").on("blur",function(){
		var $password=$(this).val();
		var $turn=false;
		if($password==""){
			$(this).parent().next().css("visibility","visible").find("span").text("密码不能为空！");
		}else if($password.length<6){
			$(this).parent().next().css("visibility","visible").find("span").text("密码太短啦，不足6个字符");
		}else if($password.length>16){
			$(this).parent().next().css("visibility","visible").find("span").text("密码太长啦，不能超过16个字符");
		}else if(!/^[a-zA-Z\d]{6,16}$/.test($password)||/^\d+$/.test(this.value)||/^[a-zA-Z]+$/.test($password)){
			$(this).parent().next().css("visibility","visible").find("span").text("请使用字母、数字组合的密码");
		}else{
			$turn=true;
		}
		if($turn==false){
			$(this).parent("label").css("border-color","#d10048");
			$zhuce=false;
		}
	})
	$("#queren-password").on("blur",function(){
		var $password1=$(this).val();
		var $password=$("#zhuce-password").val();
		var $turn=false;
		if($password1==""){
			$(this).parent().next().css("visibility","visible").find("span").text("确认密码不能为空！");
		}else if($password1!=$password){
			$(this).parent().next().css("visibility","visible").find("span").text("确认密码不一致");
		}else{
			$turn=true;
		}
		if($turn==false){
			$(this).parent("label").css("border-color","#d10048");
			$zhuce=false;
		}
	})
	$("#register-in").on("click",function(){
		var $username=$("#zhuce-phonenumber").val();
		var $password=$("#zhuce-password").val();
		var username;
		if(getCookie("MCusername")==undefined){
			username="";
		}else{
			username=getCookie("MCusername");
		}
		var password1=getCookie("MCpassword");
		$("input").each(function(){
			$(this).triggerHandler("blur");
		})
		if($("#user-agreement:checked").length==0){
			actionTip("请同意麦考林用户注册协议！");
		}else if(Register("MCusername",$username)){
			actionTip("该用户名已经被注册过！");
		}else if($zhuce){
			actionTip("恭喜注册成功！");
			if(username){
				setCookie("MCusername",username+"?"+$username,3,'/');
				setCookie("MCpassword",password1+"?"+$username+"-"+$password,3,'/');
			}else{
				setCookie("MCusername",$username,3,'/');
				setCookie("MCpassword",$username+"-"+$password,3,'/');
			}
			
		}
	})
})



